package org.scct.chenhui.dao;

import org.scct.chenhui.model.BookPublishBean;
import org.scct.chenhui.model.BookTypeBean;
import org.scct.chenhui.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookTypeDao {

    public List<BookTypeBean> getAllTypes() {
        String sql = "select * from bm_book_type";
        List<BookTypeBean> types = new ArrayList<>();
        Connection connection = DBUtils.getConnection();
        try {
            PreparedStatement pstmt = connection.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                int id = rs.getInt("id");
                String name = rs.getString("type_name");
                String remark = rs.getString("remark");
                BookTypeBean typeBean = new BookTypeBean(id, name, remark);

                types.add(typeBean);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return types;
    }
}
